package com.eeGroup.controller;

import com.eeGroup.constants.Const;
import com.eeGroup.service.LoginService;
import com.eeGroup.vo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
@Controller
public class HomeController {

    static Logger logger = LoggerFactory.getLogger(HomeController.class);

    @RequestMapping(value = {"/main","/","/welcome"})
    public ModelAndView welcome(HttpSession session,
                                HttpServletRequest request, HttpServletResponse response,
                                @RequestParam(value = "msg", required=false) String msg){

        ModelAndView model = new ModelAndView("mainPage");

        // 获取当前登录的用户
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        if(user!=null){
            model.addObject("username", user.getName());
        }
        return model;
    }

    //TODO：加载默认主页，加载用户菜单。

    @ResponseBody
    @RequestMapping(value = "/test500")
    public Object test500(HttpServletRequest request, HttpServletResponse response){

        throw new RuntimeException("1212121");
    }

}
